﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef ActionInstant_h__
#define ActionInstant_h__

#include <functional>

#include "Action.h"
#include "../utility/SmartPtrDef.h"


namespace SkyEngine2d
{
	/*!
	 \brief 描述立即执行完毕的动作,是所有立即动作的基类
	*/
	class ActionInstant
		:public ActionTime
	{
	public:
		ActionInstant();
		~ActionInstant();
		
		virtual bool isDone() const override;
	
		virtual void step(float dt) override;
		
	protected:
	
		virtual void update(float ratio);
	
		virtual void execute() = 0;
	
		virtual bool startWithTarget(IActableObject* target) override;
	
	private:
	
		virtual bool setActionTarget(IActableObject* obj) override;
	
	private:
		IActableObject* m_target;
	};
	
	
	//! 立即执行一个动作 - 函数
	/*!
		该类会在动作执行阶段立即执行一个函数，该类一般需要配合 `ActionSequence` 使用
	*/
	class ActionCallFunction
		:public ActionInstant
	{
	public:
	
		//! 创建
		/*!
		\param const std::function<void()> & func 要执行的函数
		\return ActionCallFunctionSharedPtr 
		*/
		static ActionCallFunctionSharedPtr create(const std::function<void()>& func);
	
	protected:
	
		//! 执行动作
		/*!
		\return void 
		*/
		virtual void execute()override;
	
	private:
		std::function<void()>	m_callFunc;
	};
}


#endif // ActionInstant_h__
